﻿using System.Data;

namespace DAL
{
    public class Unit_DAL : clsConnect
    {
        private static readonly clsConnect cls = new clsConnect();
        #region[Get-Data]
        public DataTable GetUnit()
        {
           cls.CreateNewSqlCommand();
            return cls.GetData("sp_tb_Unit_Search");
        }
        public DataTable GetUnitDetail_Edit(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Unit_Id", id);
            return cls.GetData("sp_tb_Unit_Detail_Edit");
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertUnit(ET.Unit_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Unit_Alias", data.Unit_Alias);
            cls.AddParameter("@Unit_Name", data.Unit_Name);
            cls.AddParameter("@Unit_Note", data.Unit_Note);
            return cls.ExecuteNonQuery("sp_tb_Unit_Insert");
        }
        public bool UpdateUnit(ET.Unit_ET data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Unit_Id", data.Unit_Id);
            cls.AddParameter("@Unit_Alias", data.Unit_Alias);
            cls.AddParameter("@Unit_Name", data.Unit_Name);
            cls.AddParameter("@Unit_Note", data.Unit_Note);
            return cls.ExecuteNonQuery("sp_tb_Unit_Update");
        }
        public bool DeleteUnit(int id)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Unit_Id", id);
            return cls.ExecuteNonQuery("sp_tb_Unit_Delete");
        }
        #endregion

        #region[Search-Fillter]
        public DataTable Search(string keywords)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter( "@KEYWORDS", keywords);
            return cls.GetData("sp_tb_Unit_Search");
        }
        #endregion
    }
}